{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ba79c76e-45f3-4d84-8e3e-700f5265d591",
   "metadata": {},
   "source": [
    "Chapter 05\n",
    "# 用嵌套列表构造矩阵\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "f93f2a0e-ce63-495e-aa77-1414d00d2670",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 用嵌套列表构造矩阵\n",
    "A = [[0,5],\n",
    "     [3,4],\n",
    "     [5,0]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "85c19159-fa6b-44a2-9c27-bc485751902f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 5]\n",
      "[[0, 5]]\n"
     ]
    }
   ],
   "source": [
    "# 取出行向量\n",
    "print(A[0])\n",
    "print([A[0]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "01698ecc-b798-4b62-ae60-9fcf7f29ac86",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 4]\n",
      "[[3, 4]]\n"
     ]
    }
   ],
   "source": [
    "print(A[1])\n",
    "print([A[1]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5dcdf379-9fb5-41ad-94d6-6e135c6e8ba2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5, 0]\n",
      "[[5, 0]]\n"
     ]
    }
   ],
   "source": [
    "print(A[2])\n",
    "print([A[2]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "bdb8fed3-03dc-44f2-9c5a-985479bfce7b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 3, 5]\n",
      "[[0], [3], [5]]\n"
     ]
    }
   ],
   "source": [
    "# 取出列向量\n",
    "print([row[0] for row in A])\n",
    "print([[row[0]] for row in A])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e990e4dc-afb8-4f99-83f7-7a338aa0c55d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5, 4, 0]\n",
      "[[5], [4], [0]]\n"
     ]
    }
   ],
   "source": [
    "print([row[1] for row in A])\n",
    "print([[row[1]] for row in A])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "179d9217",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
